﻿using System;
using System.Configuration;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace MPMovieCatalog.Settings.Sections
{
    public partial class ConnectionSection : SettingsSection
    {
        public ConnectionSection()
            : this("Соединение")
        {
        }

        public ConnectionSection(string caption)
            : base(caption)
        {
            InitializeComponent();
        }

        public override void LoadSettings()
        {
            Configuration configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            ConnectionConfigurationSection section = (ConnectionConfigurationSection)configuration.Sections["connection"];
            if (section == null)
            {
                section = new ConnectionConfigurationSection();
                section.PropertyElements.Add(new PropertyElement("host", "localhost"));
                section.PropertyElements.Add(new PropertyElement("port", "8080"));
//                section.Host = "localhost";
//                section.Port = "8080";

                configuration.Sections.Add("connection", section);
                configuration.Save();
                //                section.Host
                //hostTextBox.Text = section.Settings.Get("host").Value.ValueXml.Value;
            }
        }

        public override void SaveSettings()
        {
            Configuration configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            ClientSettingsSection section = (ClientSettingsSection)configuration.SectionGroups["userSettings"].Sections["connection"];
            if (section != null)
            {
                hostTextBox.Text = section.Settings.Get("host").Value.ToString();
            }
        }

    }

    /*    private sealed class ConnectionConfigurationSection : ConfigurationSection
        {
        }*/
}
